package com.czp.ssm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.czp.ssm.bean.Hotel;
import com.czp.ssm.bean.HotelOrder;
import com.czp.ssm.bean.Msg;
import com.czp.ssm.bean.PlaneOrder;
import com.czp.ssm.service.HotelService;

@Controller
@RequestMapping("/hotelController")
public class HotelController {

	
	@Autowired
	private HotelService hotelService;
	/**
	 * 转向酒店页面
	 * @return   
	 */
	@RequestMapping("/toHotelIndex")
	public String toHotelIndex() {
		
		return "/foreground/hotel/hotel_index";
	}
	
	/**
	 * 酒店查询回调
	 * @param user
	 * @return
	 */
	@RequestMapping("/findhotelList")
	@ResponseBody
	public Msg findhotelList(@RequestParam("cityName")String cityName,@RequestParam("startDate")String startDate,@RequestParam("endDate")String endDate) {
		List<Hotel> hotelList = hotelService.findHotelListByCityNameAndLikeKey(cityName,"");
		hotelService.getHotelByDate(hotelList,startDate);
		return Msg.success().add("hotelList", hotelList).add("cityName", cityName).add("startDate", startDate).add("endDate", endDate);
	}
	
	/**
	 * 酒店列表
	 * @param user
	 * @return
	 */
	@RequestMapping("/toHotelList")
	public ModelAndView toHotelList(@RequestParam("cityName")String cityName,@RequestParam("startDate")String startDate,@RequestParam("endDate")String endDate,@RequestParam("key")String key) {
		List<Hotel> hotelList = hotelService.findHotelListByCityNameAndLikeKey(cityName,key);
		hotelService.getHotelByDate(hotelList,startDate);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("hotelList", hotelList);
		modelAndView.addObject("cityName", cityName);
		modelAndView.addObject("startDate", startDate);
		modelAndView.addObject("endDate", endDate);
		modelAndView.setViewName("/foreground/hotel/hotel_List");
		return modelAndView;
	}
	
	
	/**
	 * 填写订单
	 * @param user
	 * @return
	 */
	@RequestMapping("/gethotelOrderEdit")
	public ModelAndView gethotelOrderEdit(@RequestParam("hotelId")String hotelId,@RequestParam("startDate")String startDate,@RequestParam("endDate")String endDate) {
		Hotel hotel = hotelService.findHotelByHotelId(hotelId);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("hotel", hotel);
		modelAndView.addObject("startDate", startDate);
		modelAndView.addObject("endDate", endDate);
		modelAndView.setViewName("/foreground/hotel/hotel_book");
		return modelAndView;
	}
	
	

	/**
	 * 提交订单
	 * @param submithotelOrder
	 * @return
	 */
	@RequestMapping(value="/submitHotelOrder" ,method=RequestMethod.POST)
	@ResponseBody
	public Msg submitHotelOrder(HotelOrder hotelOrder) {
		int flag = hotelService.saveHotelOrder(hotelOrder);
		if (flag<0) {
			return Msg.success();
		}
		return Msg.fail();
	}
	
	
	
	/**
	 * 酒店订单列表
	 * @param user
	 * @return
	 */
	@RequestMapping("/toHotelOrderList")
	public ModelAndView toHotelOrderList() {
		List<HotelOrder> hotelOrderList = hotelService.findAllHotelOrders();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("hotelOrderList",hotelOrderList);
		modelAndView.setViewName("/foreground/hotel/hotel_orderList");
		return modelAndView;
	}
	
}
